home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Learn Microsoft Visual Basic 6.0 Now
/
Learn Microsoft Visual Basic 6.0 Now (Microsoft Press)(X03-58607)(1998).ISO
/
media
/
chap10
/
b10d005.cc2
< prev
next >
Wrap
Text File
|
1998-06-07
|
4KB
|
80 lines
0, In this demonstration, I'll show you how
2, to create a simple text browser that
4, can load and display text files on your
6, system. The program uses a text box object
10, to display the file and a common dialog
12, object to open the file. The program is
16, running now, so let's see how it works.
18, I can click the File menu, and I can
21, click the Open command. And when I do, the
24, common dialog object uses the ShowOpen
26, method to display the Open dialog box. I
30, can click a text file in my dialog box,
32, and if I click the Open button, Visual
35, Basic displays it in a text box window.
38, This article is from the American Best
40, Pocket Dictionary, published in 1951, and
44, describes how to detect counterfeit
45, money. And I can see the rest of the
47, article by clicking down the scroll bars. And
54, I can click back up to the top again if
56, I want to. Notice that the program also
58, displayed the current filename in a
60, label in the top. If I want to go ahead and
63, close the file, I can click the File
64, menu and click the Close command, and it
67, will remove the output from the window.
70, And when I'm finished, I can click the
72, Exit command. Now let's take a look at how
75, this program accomplishes its work. The
78, mnuItemOpen_Click event procedure is the
81, heart of this program. The first thing
84, it does is build a wrap character that I
87, can use to add lines to my open text
91, box. And it uses the Filter property to
94, create the filter that is in the Open
96, dialog box and the ShowOpen method to open
100, the dialog box with the CommonDialog1
102, object. If the filename that was specified
107, by the user is not an empty file, then I
111, want to go ahead and open the file and
113, display it in the dialog box. The first
115, thing I do is set the MousePointer
117, property of the form to 11, which is an hour
119, glass shape because it could take a
122, little bit of time to display this if it's
123, quite a large file. And I want to use the
126, Open command to open up the file and I
130, want to set an error handler called Too
132, Big in case my file is too big to be
135, displayed in the window. If that's the
137, case, I'll have an error, and I'll jump down
139, to the label Too Big at the bottom of
140, the program and I'll use a message box to
143, say that the file is too large. And
146, I'll jump to a clean-up routine, which is
148, slightly above. And that clean-up routine
151, simply sets the mouse pointer to zero,
153, which resets its regular shape, closes
155, the file, and exits the sub-program. Now,
161, we hope this won't happen. Actually what
163, we hope happens is that I get a chance
166, to read my file in a loop. And the way
169, we do that is to read one line at a time
172, with the Line Input statement. Put that
175, into the AllText variable, and then
178, when we're all finished reading that in,
180, we'll go ahead and display that by
183, assigning AllText to the Text property of my
187, text box object. I'll set the caption of
192, the label in my program to the name of
194, the file. And I'll go ahead and enable my
198, Close item and enable my Open command
203, and my dialog box for scrolling. So that's
209, a quick look at this event procedure.
212, And we'll see that a little bit more in
213, the next demonstration when I create a
214, file editor. You might want to follow
216, these steps whenever you want to use a text
219, box in your program.
222, END